﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Zen4SyncTestServerServices;

namespace Zen4SyncOrchestrator
{
    internal static class ExtensionMethods
    {
        internal static void Call(this ChannelFactory<ITestServerServices> client, Action<ITestServerServices> action)
        {
            try
            {
                if ( client.State == CommunicationState.Closed )
                {
                    client.Open();
                }

                ITestServerServices services = client.CreateChannel();
                action(services);
            }
            catch ( Exception exception)
            {
                client.Abort();                
                throw exception;
            }
        }
    }
}
